package easy;


public class ReverseInteger {
	public static void main(String[] args) {
		System.out.println(new ReverseInteger().reverse(1534236469));
	}
    public int reverse(int x) {
    	int[] arr = new int[11];
    	int result = 0;
    	int sign = (x>0)?1:-1;
    	x = x*sign;
    	int i;
    	boolean validate = true;
    	for(i=0;i<arr.length;i++){
    		arr[i] = x%10;
    		x = x/10;
    		result = result*10;
    		result += arr[i];
    		if(x == 0)
    			break;
    	}
    	int rank =1;
    	int temp = result;
    	for(int j = i; j>=0 ;j--){
    		rank = temp % 10;
    		if(rank != arr[j])
    		{
    			validate =false;
    			break;
    		}
    		temp = temp/10;
    	}
    	if(validate)
    		return sign*result;
    	else
    		return 0;
    }
}
